// JavaScript Document
function formatMoney(s, type) {
    if (/[^0-9\.]/.test(s)) return "0";
    if (s == null || s == "") return "0";
    s = s.toString().replace(/^(\d*)$/, "$1.");
    s = (s + "0000").replace(/(\d*\.\d\d\d\d)\d*/, "$1");
    s = s.replace(".", ",");
    var re = /(\d)(\d{3},)/;
    while (re.test(s))
        s = s.replace(re, "$1,$2");
    s = s.replace(/,(\d\d\d\d)$/, ".$1");
    if (type == 0) {// 不带小数位(默认是有小数位)
        var a = s.split(".");
        if (a[1] == "00") {
            s = a[0];
        }
    }
    return s;
}

function commafyback(num) 
{ 
var x = num.split(','); 
return parseFloat(x.join("")); 
} 

//求和的算法
function tsum(rs,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11){
	var t1 = (document.getElementById(t1)==null)?"0":document.getElementById(t1).value;
	var t2 = (document.getElementById(t2)==null)?"0":document.getElementById(t2).value;
	var t3 = (document.getElementById(t3)==null)?"0":document.getElementById(t3).value;
	var t4 = (document.getElementById(t4)==null)?"0":document.getElementById(t4).value;
	var t5 = (document.getElementById(t5)==null)?"0":document.getElementById(t5).value;
	var t6 = (document.getElementById(t6)==null)?"0":document.getElementById(t6).value;
	var t7 = (document.getElementById(t7)==null)?"0":document.getElementById(t7).value;
	var t8 = (document.getElementById(t8)==null)?"0":document.getElementById(t8).value;
	var t9 = (document.getElementById(t9)==null)?"0":document.getElementById(t9).value;
	var t10 = (document.getElementById(t10)==null)?"0":document.getElementById(t10).value;
	var t11 = (document.getElementById(t11)==null)?"0":document.getElementById(t11).value;

	t1=(t1.indexOf(',')>0)?commafyback(t1):t1;
	t2=(t2.indexOf(',')>0)?commafyback(t2):t2;
	t3=(t3.indexOf(',')>0)?commafyback(t3):t3;
	t4=(t4.indexOf(',')>0)?commafyback(t4):t4;
	t5=(t5.indexOf(',')>0)?commafyback(t4):t5;
	t6=(t6.indexOf(',')>0)?commafyback(t4):t6;
	t7=(t7.indexOf(',')>0)?commafyback(t4):t7;
	t8=(t8.indexOf(',')>0)?commafyback(t4):t8;
	t9=(t9.indexOf(',')>0)?commafyback(t4):t9;
	t10=(t10.indexOf(',')>0)?commafyback(t10):t10;
	t11=(t11.indexOf(',')>0)?commafyback(t11):t11;


	var in1=parseFloat(t1)*1000000000000;
	var in2=parseFloat(t2)*1000000000000;	
	var in3=parseFloat(t3)*1000000000000;	
	var in4=parseFloat(t4)*1000000000000;	
	var in5=parseFloat(t5)*1000000000000;
	var in6=parseFloat(t6)*1000000000000;
	var in7=parseFloat(t7)*1000000000000;
	var in8=parseFloat(t8)*1000000000000;
	var in9=parseFloat(t9)*1000000000000;
	var in10=parseFloat(t10)*1000000000000;
	var in11=parseFloat(t11)*1000000000000;
	
	var sum=in1+in2+in3+in4+in5+in6+in7+in8+in9+in10+in11;
	sum=sum/1000000000000;
	//document.getElementById(rs).value=formatMoney(sum);
	
	sum=sum.toFixed(2);
	document.getElementById(rs).value=sum;
}

//乘积的算法
function tmulti(rs,t1,t2,t3,t4,t5,t6,t7,t8,t9){
	var t1 = (document.getElementById(t1)==null)?"0":document.getElementById(t1).value;
	var t2 = (document.getElementById(t2)==null)?"0":document.getElementById(t2).value;
	var t3 = (document.getElementById(t3)==null)?"0":document.getElementById(t3).value;
	var t4 = (document.getElementById(t4)==null)?"0":document.getElementById(t4).value;
	var t5 = (document.getElementById(t5)==null)?"0":document.getElementById(t5).value;
	var t6 = (document.getElementById(t6)==null)?"0":document.getElementById(t6).value;
	var t7 = (document.getElementById(t7)==null)?"0":document.getElementById(t7).value;
	var t8 = (document.getElementById(t8)==null)?"0":document.getElementById(t8).value;
	var t9 = (document.getElementById(t9)==null)?"0":document.getElementById(t9).value;


	t1=(t1.indexOf(',')>0)?commafyback(t1):t1;
	t2=(t2.indexOf(',')>0)?commafyback(t2):t2;
	t3=(t3.indexOf(',')>0)?commafyback(t3):t3;
	t4=(t4.indexOf(',')>0)?commafyback(t4):t4;
	t5=(t5.indexOf(',')>0)?commafyback(t4):t5;
	t6=(t6.indexOf(',')>0)?commafyback(t4):t6;
	t7=(t7.indexOf(',')>0)?commafyback(t4):t7;
	t8=(t8.indexOf(',')>0)?commafyback(t4):t8;
	t9=(t9.indexOf(',')>0)?commafyback(t4):t9;

	var in1=parseFloat(t1);
	var in2=parseFloat(t2);	
	var in3=parseFloat(t3);	
	var in4=parseFloat(t4);	
	var in5=parseFloat(t5);
	var in6=parseFloat(t6);
	var in7=parseFloat(t7);
	var in8=parseFloat(t8);
	var in9=parseFloat(t9);
	
	in1=(in1==0)?1:in1;
	in2=(in2==0)?1:in2;
	in3=(in3==0)?1:in3;
	in4=(in4==0)?1:in4;
	in5=(in5==0)?1:in5;
	in6=(in6==0)?1:in6;
	in7=(in7==0)?1:in7;
	in8=(in8==0)?1:in8;
	in9=(in9==0)?1:in9;
	
	var multi=in1*in2*in3*in4*in5*in6*in7*in8*in9;
	//alert(multi);
	//document.getElementById(rs).value=formatMoney(multi);
	multi=multi.toFixed(2);
	document.getElementById(rs).value=multi;
}


